<?php
/**
 * PollingController.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-09-02 11:10:35
 * @modified    2023-09-02 11:10:35
 *
 */

namespace App\Http\Controllers;

use App\Repositories\PollingRepo;
use Illuminate\Http\Request;

class PollingController extends BaseModuleController
{
    public function params(Request $request)
    {
        return message('获取成功', true, PollingRepo::params());
    }

    public function counts(Request $request)
    {
        try {
            $data = PollingRepo::counts();
            return message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function index(Request $request)
    {
        try {
            $export = intval(\request('export', ''));
            $data = PollingRepo::getList();
            if ($export) {
                return message('获取成功', true, $data);
            }
            return list_message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function process(Request $request, $id)
    {
        try {
            $data = PollingRepo::process($id);
            return message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function accept(Request $request, $id)
    {
        try {
            $data = PollingRepo::accept($id);
            return message('接受成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function start(Request $request, $id)
    {
        try {
            $data = PollingRepo::start($id);
            return message('开始成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function receipt(Request $request, $id)
    {
        try {
            $data = PollingRepo::receipt($id);
            return message('回执成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function show(Request $request, $id)
    {
        try {
            $polling = PollingRepo::getDetail($id);
            return message('获取成功', true, $polling);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function delete(Request $request, $id)
    {
        try {
            PollingRepo::delete($id);
            return message('删除成功', true, null);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function store(Request $request)
    {
        try {
            $data = PollingRepo::store();
            return message('保存成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }
}